package com.tfjybj.itoo.exam.provider.controller;

import org.apache.dubbo.config.annotation.Reference;;
import com.dmsdbj.itoo.tool.business.ItooResult;
import com.github.pagehelper.PageInfo;
import com.tfjybj.itoo.exam.provider.service.TrainingProgramsService;
import com.tfjybj.itoo.teach.FacadeApi.TrainingProgramsApi;
import com.tfjybj.itoo.teach.entity.TrainingProgramsEntity;
import com.tfjybj.itoo.teach.model.TrainingProgramsModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * TrainingProgramsController
 * trainingPrograms表
 *
 * @author 杨江涛
 * @version 2.0.0
 * @since 2.0.0 2018-11-15 10:35:56
 */
@Api(tags = {"trainingPrograms表接口"})
@RequestMapping(value = "/trainingPrograms")
@RestController
public class TrainingProgramsController {

    @Resource
    private TrainingProgramsService trainingProgramsService;

    @Reference(check = false)
    private TrainingProgramsApi trainingProgramsApi;

    //region 模板生成：基本增删改

    /**
     * 添加
     *
     * @param model TrainingProgramsModel
     * @return 添加的结果
     * @author 杨江涛
     * @since 2.0.0 2018-11-15 10:35:56
     */
    @ApiOperation(value = "添加")
    @PostMapping(value = {"/create"})
    public ItooResult create(@RequestBody TrainingProgramsModel model) {
        if (StringUtils.isEmpty(model.getCourseId())) {
            return ItooResult.build(ItooResult.FAIL, "courseId为空");
        }
        if (StringUtils.isEmpty(model.getProfessionId())) {
            return ItooResult.build(ItooResult.FAIL, "professionId为空");
        }
        if (StringUtils.isEmpty(model.getSemesterId())) {
            return ItooResult.build(ItooResult.FAIL, "semesterId为空");
        }
        trainingProgramsApi.create(model);
        return ItooResult.build(ItooResult.SUCCESS, "添加成功");
    }

    /**
     * 删除
     *
     * @param id 主键id
     * @return ItooResult 是否删除成功
     * @author 杨江涛
     * @since 2.0.0 2018-11-15 10:35:56
     */
    @ApiOperation(value = "根据id删除（单个）")
    @DeleteMapping(value = {"/delete/{id}"})
    public ItooResult delete(@ApiParam(value = "主键id", required = true) @PathVariable String id) {
        trainingProgramsApi.delete(id);
        return ItooResult.build(ItooResult.SUCCESS, "删除成功");
    }

    /**
     * 批量删除
     *
     * @param ids ids
     * @return ItooResult 批量删除是否成功结果
     * @author 杨江涛
     * @since 2.0.0 2018-11-15 10:35:56
     */
    @ApiOperation(value = "根据id批量删除")
    @DeleteMapping(value = {"/deleteByIds"})
    @ApiImplicitParam(name = "ids", value = "ids", dataType = "List<String>", required = true)
    public ItooResult deleteByIds(@RequestBody List<String> ids) {
        trainingProgramsApi.deleteByIds(ids);
        return ItooResult.build(ItooResult.SUCCESS, "批量删除成功");
    }

    /**
     * 修改
     *
     * @param model TrainingProgramsModel
     * @return 修改后的结果
     * @author 杨江涛
     * @since 2.0.0 2018-11-15 10:35:56
     */
    @ApiOperation(value = "根据id修改trainingPrograms")
    @PutMapping(value = {"/modify"})
    public ItooResult modify(@RequestBody TrainingProgramsModel model) {
        if (StringUtils.isEmpty(model.getCourseId())) {
            return ItooResult.build(ItooResult.FAIL, "courseId为空");
        }
        if (StringUtils.isEmpty(model.getProfessionId())) {
            return ItooResult.build(ItooResult.FAIL, "professionId为空");
        }
        if (StringUtils.isEmpty(model.getSemesterId())) {
            return ItooResult.build(ItooResult.FAIL, "semesterId为空");
        }
        trainingProgramsApi.modify(model);
        return ItooResult.build(ItooResult.SUCCESS, "修改成功");
    }

    /**
     * 根据id查找TrainingPrograms
     *
     * @param id 主键id
     * @author 杨江涛
     * @since 2.0.0 2018-11-15 10:35:56
     */
    @ApiOperation(value = "根据id查询")
    @GetMapping(value = {"/findById/{id}"})
    public ItooResult findById(@ApiParam(value = "主键id", required = true) @PathVariable String id) {
        TrainingProgramsEntity trainingProgramsEntity = trainingProgramsApi.findById(id);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", trainingProgramsEntity);
    }

    /**
     * 分页查询所有TrainingPrograms
     *
     * @param pageNo   页码
     * @param pageSize 每页条数
     * @author 杨江涛
     * @since 2.0.0 2018-11-15 10:35:56
     */
    @ApiOperation(value = "分页查询所有TrainingPrograms")
    @GetMapping(value = {"/queryPageAll/{pageNo}/{pageSize}"})
    public ItooResult queryPageAll(@ApiParam(name = "pageNo", value = "页码", required = true, example = "1") @PathVariable Integer pageNo,
                                   @ApiParam(name = "pageSize", value = "页数", required = true, example = "10") @PathVariable Integer pageSize) {
        PageInfo<TrainingProgramsEntity> trainingProgramss = trainingProgramsApi.queryPageAll(pageNo, pageSize);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", trainingProgramss);
    }

    /**
     * 根据课程_id模糊查询trainingPrograms
     *
     * @param courseId 课程_id
     * @param pageNo   页码
     * @param pageSize 页数
     * @return 模糊查询的trainingPrograms
     * @author 杨江涛
     * @since 2.0.0 2018-11-15 10:35:56
     */
    @ApiOperation(value = "根据课程_id模糊查询trainingPrograms", notes = "分页根据课程_id模糊查询trainingPrograms")
    @GetMapping(value = "queryTrainingProgramsByLikeCourseId/{pageNo}/{pageSize}")
    public ItooResult queryTrainingProgramsByLikeCourseId(@RequestParam(required = false, defaultValue = "") String courseId,
                                                          @ApiParam(value = "页码", required = true, example = "1") @PathVariable Integer pageNo,
                                                          @ApiParam(value = "记录数", required = true, example = "10") @PathVariable Integer pageSize) {
        PageInfo<TrainingProgramsEntity> trainingProgramsList = trainingProgramsApi.queryByCourseId(courseId, pageNo, pageSize);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", trainingProgramsList);
    }
    //endregion

    /* **********************************以下为非模板生成的内容********************************* */

    /**
     * 无参查询当前学年课程id
     *
     * @return 当前学年课程ID
     * @author 杨江涛
     * @since 2.0.0 2018-11-24 19:06:34
     */
    @ApiOperation(value = "查询无参查询当前学年课程id")
    @PostMapping(value = {"/findCourseId"})
    public ItooResult findCourseId() {
        List<TrainingProgramsEntity> trainingProgramsEntityList = trainingProgramsService.findCourseId();
        return ItooResult.build(ItooResult.SUCCESS, "当前课程ID查询成功", trainingProgramsEntityList);
    }

    /**
     * 根据专业id查询当前学年课程
     *
     * @param professionId 专业id
     * @return 当前学年课程信息
     * @author 杨江涛
     * @since 2.0.0 2018-11-25 10:53:34
     */
    @ApiOperation(value = "根据专业id查询当前学年课程信息")
    @GetMapping(value = {"/findByProfessionId/{professionId}"})
    public ItooResult findByProfessionId(@ApiParam(value = "专业professionId", required = true) @PathVariable String professionId) {
        List<TrainingProgramsModel> trainingProgramsModelList = trainingProgramsService.findByProfessionId(professionId);
        return ItooResult.build(ItooResult.SUCCESS, "根据专业ID查询当前学年课程信息成功", trainingProgramsModelList);
    }

    /**
     * 根据专业id查询当前学年课程(与course表联表查询)
     *
     * @param professionId 专业id
     * @return 当前学年课程信息
     * @author 杨江涛
     * @since 2.0.0 2018-12-4 14:41:59
     */
    @ApiOperation(value = "根据专业id查询当前学年课程(与course表联表查询)")
    @GetMapping(value = {"/findCourseByProfessionId/{professionId}"})
    public ItooResult findCourseByProfessionId(@ApiParam(value = "专业professionId", required = true) @PathVariable String professionId) {
        List<TrainingProgramsModel> trainingProgramsModelList = trainingProgramsService.findCourseByProfessionId(professionId);
        return ItooResult.build(ItooResult.SUCCESS, "根据专业ID联表查询当前学年课程信息成功", trainingProgramsModelList);
    }
}

